package com.qpkj.web.controller.oms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.qpkj.oms.parameter.AddAchievementVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.qpkj.common.annotation.Log;
import com.qpkj.common.core.controller.BaseController;
import com.qpkj.common.core.domain.AjaxResult;
import com.qpkj.common.enums.BusinessType;
import com.qpkj.oms.domain.OmsAchievement;
import com.qpkj.oms.service.IOmsAchievementService;
import com.qpkj.common.utils.poi.ExcelUtil;
import com.qpkj.common.core.page.TableDataInfo;

/**
 * 员工业绩Controller
 *
 * @author ruoyi
 * @date 2022-12-20
 */
@RestController
@RequestMapping("/oms/achievement")
public class OmsAchievementController extends BaseController {
    @Autowired
    private IOmsAchievementService omsAchievementService;

    /**
     * 查询员工业绩列表
     */
   // @PreAuthorize("@ss.hasPermi('oms:achievement:list')")
    @GetMapping("/list")
    public TableDataInfo list(OmsAchievement omsAchievement) {
        startPage();
        List<OmsAchievement> list = omsAchievementService.selectOmsAchievementList(omsAchievement);
        return getDataTable(list);
    }

    /**
     * 导出员工业绩列表
     */
    //@PreAuthorize("@ss.hasPermi('oms:achievement:export')")
    @Log(title = "员工业绩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsAchievement omsAchievement) {
        List<OmsAchievement> list = omsAchievementService.selectOmsAchievementList(omsAchievement);
        ExcelUtil<OmsAchievement> util = new ExcelUtil<OmsAchievement>(OmsAchievement.class);
        util.exportExcel(response, list, "员工业绩数据");
    }

    /**
     * 获取员工业绩详细信息
     */
    @PreAuthorize("@ss.hasPermi('oms:achievement:query')")
    @GetMapping(value = "/{achievementId}")
    public AjaxResult getInfo(@PathVariable("achievementId") Long achievementId) {
        return success(omsAchievementService.selectOmsAchievementByAchievementId(achievementId));
    }

    /**
     * 新增员工业绩
     */
    @PreAuthorize("@ss.hasPermi('oms:achievement:add')")
    @Log(title = "员工业绩", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsAchievement omsAchievement) {
        return toAjax(omsAchievementService.insertOmsAchievement(omsAchievement));
    }

    /**
     * 新增员工业绩
     *
     * @return
     */
   // @PreAuthorize("@ss.hasPermi('oms:achievement:add')")
    @Log(title = "员工业绩", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addAchievement")
    public AjaxResult addAchievement(@RequestBody AddAchievementVo addAchievementVo) {
        return omsAchievementService.addAchievement(addAchievementVo);
    }

    /**
     * 修改员工业绩
     */
    @PreAuthorize("@ss.hasPermi('oms:achievement:edit')")
    @Log(title = "员工业绩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsAchievement omsAchievement) {
        return toAjax(omsAchievementService.updateOmsAchievement(omsAchievement));
    }

    /**
     * 删除员工业绩
     */
    @PreAuthorize("@ss.hasPermi('oms:achievement:remove')")
    @Log(title = "员工业绩", businessType = BusinessType.DELETE)
    @DeleteMapping("/{achievementIds}")
    public AjaxResult remove(@PathVariable Long[] achievementIds) {
        return toAjax(omsAchievementService.deleteOmsAchievementByAchievementIds(achievementIds));
    }
}
